<?php
namespace App\Api\Controllers;
use Common\ApiController;

class GoldbeanController extends ApiController
{
    public function initialize()
    {
        parent::initialize();
    }


    /**
     * @Inject
     * @var IGoldBeanService
     */
    protected $services;


    /**
     * 获取金豆任务列表
     * @GetMapping("goldTaskList")
     * @return ResponseInterface
     */
    public function goldTaskList()
    {
        $userInfo = Context::get(ContextKey::USER_INFO);
        return $this->services->goldTaskList($userInfo['user_id']);
    }

    /**
     * 签到列表
     * @GetMapping("signInList")
     * @return ResponseInterface
     */
    public function signInList(){
        $userInfo = Context::get(ContextKey::USER_INFO);
        return $this->services->signInList($userInfo['user_id']);
    }


    /**
     * @GetMapping("signIn")
     * 用户签到
     */
    public function signIn(){
        $userInfo = Context::get(ContextKey::USER_INFO);
        return $this->services->signIn($userInfo['user_id']);
    }


    /**
     * 金豆去完成任务
     * @GetMapping("taskType")
     */
    public function taskType(Request $request){
        $taskId = $request->input("taskId","");
        if(!isset($taskId) || empty($taskId)){
            return $this->error("任务id不能为空");
        }else{
            if(!in_array($taskId,[4,6])){
                return $this->error("类型错误");
            }
        }
        $userInfo = Context::get(ContextKey::USER_INFO);
        return $this->services->taskType($userInfo['user_id'],$taskId);
    }



    /**
     * 金豆去完成任务
     * @GetMapping("goldBeanLog")
     */
    public function goldBeanLog(Request $request){
        $page = $request->input("page","1");
        $pageSize = $request->input("pageSize","10");
        $userInfo = Context::get(ContextKey::USER_INFO);
        return $this->services->goldBeanLog($userInfo['user_id'],(int)$page,(int)$pageSize);
    }


    /**
     * 金豆商城列表
     * @GetMapping("selfGoodsList")
     */
    public function selfGoodsList(Request $request){
        $page = $request->input("page","1");
        $pageSize = $request->input("pageSize","10");
        return $this->services->selfGoodsList((int)$page,(int)$pageSize);
    }



}